Move more of times into accessors, more modern times.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 17 Jun 2013 05:12:58 +0000 (05:12 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 17 Jun 2013 05:12:58 +0000 (05:12 +0000)
Many of the remaining explicit accesses to wpt->microseconds aren't actually
 using it as microseconds at all, but rather as a generic integer. :-(

24 files changed:
gpsbabel/GPSBabel.xcodeproj/project.xcworkspace/xcuserdata/robertlipe.xcuserdatad/UserInterfaceState.xcuserstate
gpsbabel/cetus.cc
gpsbabel/csv_util.cc
gpsbabel/defs.h
gpsbabel/delbin.cc
gpsbabel/glogbook.cc
gpsbabel/gpx.cc
gpsbabel/gtm.cc
gpsbabel/gtrnctr.cc
gpsbabel/html.cc
gpsbabel/itracku.cc
gpsbabel/kml.cc
gpsbabel/lowranceusr4.cc
gpsbabel/magnav.cc
gpsbabel/mapsend.cc
gpsbabel/nmea.cc
gpsbabel/osm.cc
gpsbabel/palmdoc.cc
gpsbabel/pathaway.cc
gpsbabel/text.cc
gpsbabel/unicsv.cc
gpsbabel/waypt.cc
gpsbabel/wfff_xml.cc
gpsbabel/xol.cc

index f504b6e2d70cb1619d3d9564a1e21cc99f361092..07c201120910f84287f6fcb3ec9b3ec8d79c9455 100644 (file)
Binary files a/gpsbabel/GPSBabel.xcodeproj/project.xcworkspace/xcuserdata/robertlipe.xcuserdatad/UserInterfaceState.xcuserstate and b/gpsbabel/GPSBabel.xcodeproj/project.xcworkspace/xcuserdata/robertlipe.xcuserdatad/UserInterfaceState.xcuserstate differ
index 022d22cec47d57be8204d9654a7d68f8624da171..fc31bd5a9c58ae923844be242ea3101ebf67009b 100644 (file)
@@ -210,8 +210,8 @@ read_track_point(cetus_track_point_t* data, const time_t basetime)
     break;                     /* no GPS */
   }
 
-  wpt->creation_time = basetime +
-                       ((data->hour & 0x1F) * 3600) + (data->min * 60) + data->sec;
+  wpt->SetCreationTime(basetime +
+                       ((data->hour & 0x1F) * 3600) + (data->min * 60) + data->sec);
   if (data->dsec) {
     wpt->microseconds = (int)data->dsec * 10000;
   }
index a13028360d2d94b1e23d32bfc6e75180bd7ac4ff..56eedd332bafe70cff4fb7b99401fb0c65f9639e 100644 (file)
@@ -1220,7 +1220,7 @@ xcsv_parse_val(const char* s, waypoint* wpt, const field_map_t* fmp,
     break;
   case XT_ISO_TIME:
   case XT_ISO_TIME_MS:
-    wpt->creation_time = xml_parse_time(s, &wpt->microseconds);
+    wpt->creation_time = xml_parse_time(s);
     break;
   case XT_NET_TIME: {
     time_t tt = wpt->GetCreationTime();
index 7256c5ca9ed94820b19d73c8e91d5ca29d02c806..a75af4bb51bd8d7bcc7fee002baa3cd1a3b33de6 100644 (file)
@@ -34,6 +34,7 @@
 #include "inifile.h"
 #include "session.h"
 
+#include <QtCore/QDebug>
 # include "src/core/datetime.h"
 
 // Turn on Unicode in expat?
@@ -526,11 +527,23 @@ public:
   wp_flags wpt_flags;
   QString icon_descr;
 
-  gpsbabel::DateTime  GetCreationTime() const { return creation_time; }
-  void SetCreationTime(time_t t) { creation_time = t; }
+  gpsbabel::DateTime  GetCreationTime() const {
+//QDateTime dt(creation_time);
+//qDebug() << dt.toString("dd.MM.yyyy hh:mm:ss.zzz");
+//fprintf(stderr, "ng %d\n", (int)creation_time);
+   return creation_time;
+}
+  void SetCreationTime(gpsbabel::DateTime t) { creation_time = t; 
+//qDebug() << t.toString("dd.MM.yyyy hh:mm:ss.zzz");
+//fprintf(stderr, "ns %d\n", (int)t);
+}
+  void SetCreationTime(time_t t) { creation_time = t; 
+//fprintf(stderr, "t %d\n", (int)t);
+}
   void SetCreationTime(time_t t, int us) {
     creation_time = t; 
     microseconds = us;
+//fprintf(stderr, "t/us %d %d\n", (int)t, us);
   }
   gpsbabel::DateTime creation_time;
   int microseconds;    /* Optional millionths of a second. */
@@ -1017,7 +1030,7 @@ const char* get_filename(const char* fname);                      /* extract the filename portion *
 #define str_iso8859_1_to_utf8(str) cet_str_iso8859_1_to_utf8((str))
 
 /* this lives in gpx.c */
-gpsbabel::DateTime xml_parse_time(const char* cdatastr, int* microsecs);
+gpsbabel::DateTime xml_parse_time(const char* cdatastr);
 
 xml_tag* xml_findfirst(xml_tag* root, const char* tagname);
 xml_tag* xml_findnext(xml_tag* root, xml_tag* cur, const char* tagname);
index 5fd44609adffb85025a45ef7266f9ee969440764..bf3f05c3f8fb6289bf11ba908aec8574a1ea4221 100644 (file)
@@ -1279,7 +1279,7 @@ get_gc_notes(const waypoint* wp, int* symbol, char** notes, unsigned* notes_size
       }
       logpart = xml_findfirst(curlog, "groundspeak:date");
       if (logpart) {
-        time_t logtime = xml_parse_time(logpart->cdata, NULL);
+        time_t logtime = xml_parse_time(logpart->cdata);
         const struct tm* logtm = gmtime(&logtime);
         gbfprintf(fd, "%d-%02d-%02d ", logtm->tm_year + 1900, logtm->tm_mon + 1, logtm->tm_mday);
       }
index cbdd0773301a5efeca1807b3f48bb68f7d40a1a9..698c997bdbe03c26cc3e78acb6c555be78f7a404 100644 (file)
@@ -147,7 +147,7 @@ void        gl_trk_pnt_e(const char* args, const char** unused)
 
 void   gl_trk_utc(const char* args, const char** unused)
 {
-  wpt_tmp->SetCreationTime(xml_parse_time(args, &wpt_tmp->microseconds));
+  wpt_tmp->SetCreationTime(xml_parse_time(args));
 }
 
 void   gl_trk_lat(const char* args, const char** unused)
index 03fe746b51e566af9bdd4b248d37981ece1396b7..594c9f2f78baa3d2c9478bf6042dd13e7194ff23 100644 (file)
@@ -846,7 +846,7 @@ gs_get_container(geocache_container t)
 }
 
 gpsbabel::DateTime
-xml_parse_time(const char* cdatastr, int* microsecs)
+xml_parse_time(const char* cdatastr)
 {
   int off_hr = 0;
   int off_min = 0;
@@ -884,14 +884,16 @@ xml_parse_time(const char* cdatastr, int* microsecs)
     }
   }
 
+  double fsec = 0;
   pointstr = strchr(timestr, '.');
   if (pointstr) {
+    sscanf(pointstr, "%le", &fsec);
+#if 0
+    /* Round to avoid FP jitter */
     if (microsecs) {
-      double fsec;
-      sscanf(pointstr, "%le", &fsec);
-      /* Round to avoid FP jitter */
       *microsecs = .5 + (fsec * 1000000.0) ;
     }
+#endif
     *pointstr = '\0';
   }
 
@@ -917,9 +919,9 @@ xml_parse_time(const char* cdatastr, int* microsecs)
   // 2038 but which we can't replace until Steven upgrades Qt.
   // Baby steps.
   QDateTime dt = QDateTime::fromTime_t(rv);
-  if (microsecs) {
-    dt = dt.addMSecs(*microsecs / 1000);
-// qDebug() << dt.toString("dd.MM.yyyy hh:mm:ss.zzz")  << " ZZZ " << *microsecs;
+  if (fsec) {
+    dt = dt.addMSecs(fsec * 1000);
+// qDebug() << dt.toString("dd.MM.yyyy hh:mm:ss.zzz")  << " ZZZ " << fsec;
   }
   return dt;
 }
@@ -1025,7 +1027,7 @@ gpx_end(void* data, const XML_Char* xml_el)
     waypt_alloc_gc_data(wpt_tmp)->placer = xstrdup(cdatastrp);
     break;
   case tt_cache_log_date:
-    gc_log_date = xml_parse_time(cdatastrp, NULL);
+    gc_log_date = xml_parse_time(cdatastrp);
     break;
     /*
      * "Found it" logs follow the date according to the schema,
@@ -1143,7 +1145,7 @@ gpx_end(void* data, const XML_Char* xml_el)
   case tt_wpt_time:
   case tt_trk_trkseg_trkpt_time:
   case tt_rte_rtept_time:
-    wpt_tmp->SetCreationTime(xml_parse_time(cdatastrp, &wpt_tmp->microseconds));
+    wpt_tmp->SetCreationTime(xml_parse_time(cdatastrp));
     break;
   case tt_wpt_cmt:
   case tt_rte_rtept_cmt:
index 830465f3bf3ff67ca4a9ef78dc1116c1361509f3..3175ff00da299a330f09070ad251b38bf335888c 100644 (file)
@@ -660,7 +660,7 @@ gtm_read(void)
     wpt->latitude = fread_double(file_in);
     wpt->longitude = fread_double(file_in);
     convert_datum(&wpt->latitude, &wpt->longitude);
-    wpt->creation_time = fread_long(file_in);
+    wpt->SetCreationTime(fread_long(file_in));
     if (wpt->creation_time) {
       wpt->creation_time += EPOCH89DIFF;
     }
index 57e4d8edabfb20dd8b87d4e3fa9a4b30d324d468..b41d072be6f26bcfddd39bdf13ca23a1a8446f32 100644 (file)
@@ -519,7 +519,7 @@ gtc_trk_pnt_e(const char* args, const char** unused)
 void
 gtc_trk_utc(const char* args, const char** unused)
 {
-  wpt_tmp->creation_time = xml_parse_time(args, NULL);
+  wpt_tmp->creation_time = xml_parse_time(args);
 }
 
 void
index 42c6f7c9dd9828aef0a62b64a0aec8996e778584..bf039787b72f4f6f6330623c48f4355a52326aa2 100644 (file)
@@ -186,7 +186,7 @@ html_disp(const waypoint* wpt)
 
       logpart = xml_findfirst(curlog, "groundspeak:date");
       if (logpart) {
-        logtime = xml_parse_time(logpart->cdata, NULL);
+        logtime = xml_parse_time(logpart->cdata);
         logtm = localtime(&logtime);
         if (logtm) {
           gbfprintf(file_out,
index 8efd03c05e0167942c0be30fcdf7231a243e7189..36e1402e055d984c2f29f503eaa94b50f40212f8 100644 (file)
@@ -662,14 +662,12 @@ static void
 nmea_set_waypoint_time(waypoint* wpt, struct tm* time, int microseconds)
 {
   if (time->tm_year == 0) {
-    wpt->creation_time = ((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec;
-    wpt->microseconds = microseconds;
+    wpt->SetCreationTime(((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec, microseconds);
     if (wpt->wpt_flags.fmt_use == 0) {
       wpt->wpt_flags.fmt_use = 1;
     }
   } else {
-    wpt->creation_time = mkgmtime(time);
-    wpt->microseconds = microseconds;
+    wpt->SetCreationTime(mkgmtime(time), microseconds);
     if (wpt->wpt_flags.fmt_use != 0) {
       wpt->wpt_flags.fmt_use = 0;
     }
index 1bd895ec6ec2049f3d6b7c6f5064877e9853be95..059ced51893a70a7b4f5d3f0ab7b64bcf0a98c32 100644 (file)
@@ -319,7 +319,7 @@ void wpt_desc(const char* args, const char** unused)
 
 void wpt_time(const char* args, const char** unused)
 {
-  wpt_tmp->creation_time = xml_parse_time(args, &wpt_tmp->microseconds);
+  wpt_tmp->creation_time = xml_parse_time(args);
 }
 
 void wpt_coord(const char* args, const char** attrv)
@@ -1349,7 +1349,7 @@ char* kml_geocache_get_logs(const waypoint* wpt)
 
     logpart = xml_findfirst(curlog, "groundspeak:date");
     if (logpart) {
-      logtime = xml_parse_time(logpart->cdata, NULL);
+      logtime = xml_parse_time(logpart->cdata);
       struct tm* logtm = localtime(&logtime);
       if (logtm) {
         char* temp;
index 294ba6c14f577dda6ea8e741aade2a8823b59413..db8ccfaa37e27f0b39f283c7a0530e609bb5a7a4 100644 (file)
@@ -441,8 +441,8 @@ lowranceusr4_parse_waypoints(void)
     // with, as a practical matter, we have no date, so don't even compute
     // or set it.
     if (create_date > 2440587) {
-      wpt_tmp->creation_time = lowranceusr4_get_timestamp(create_date,
-                                                          create_time);
+      wpt_tmp->SetCreationTime(lowranceusr4_get_timestamp(create_date,
+                                                          create_time));
     }
 
     /* Unused byte */
@@ -810,8 +810,8 @@ lowranceusr4_waypt_disp(const waypoint* wpt)
   gbfputflt(WAYPT_GET(wpt, proximity, 0.0), file_out);
 
   /* Creation date/time */
-  gbfputint32(lowranceusr4_jd_from_timestamp(wpt->creation_time), file_out);
-  gbfputint32(wpt->creation_time, file_out);
+  gbfputint32(lowranceusr4_jd_from_timestamp(wpt->GetCreationTime()), file_out);
+  gbfputint32(wpt->GetCreationTime(), file_out);
 
   /* Unused byte */
   gbfputc(0, file_out);
@@ -982,7 +982,7 @@ lowranceusr4_write_track_waypt(const waypoint* wpt)
   gbfputc(0, file_out);
 
   /* Timestamp */
-  gbfputint32(wpt->creation_time, file_out);
+  gbfputint32(wpt->GetCreationTime(), file_out);
 
   /* Long/Lat */
   gbfputdbl(wpt->longitude * DEGREESTORADIANS, file_out);
index 4ec0a6f1cd27c7e8be39aa4940380a3c197d0d03..df2dabf8a09d6a599931ee80384f3596d507840b 100644 (file)
@@ -120,7 +120,7 @@ data_read(void)
     tm.tm_mon = be_read16(&rec->crt_mon) - 1;
     tm.tm_year = be_read16(&rec->crt_year) - 1900;
     if (mkgmtime(&tm) > 0) {
-      wpt_tmp->creation_time = mktime(&tm);
+      wpt_tmp->SetCreationTime(mktime(&tm));
     }
     waypt_add(wpt_tmp);
 
index 8ae4e2e033745b0def4ec00ae51a9fd69e0442f1..540b040c961407fdf872d4a0bb794ea87ccb0051 100644 (file)
@@ -214,7 +214,7 @@ mapsend_track_read(void)
     if (wpt_tmp->altitude < unknown_alt + 1) {
       wpt_tmp->altitude = unknown_alt;
     }
-    wpt_tmp->creation_time = gbfgetint32(mapsend_file_in);
+    time_t t = gbfgetint32(mapsend_file_in);
     valid = gbfgetint32(mapsend_file_in);
 
     /* centiseconds only in >= version 3.0 */
@@ -223,7 +223,7 @@ mapsend_track_read(void)
     } else {
       centisecs = 0;
     }
-    wpt_tmp->microseconds = CENTI_TO_MICRO(centisecs);
+    wpt_tmp->SetCreationTime(t, CENTI_TO_MICRO(centisecs));
 
     track_add_wpt(track_head, wpt_tmp);
   }
index f939bbf42397aa452d120dabfb320574f34c4479..d688176d418ad3e0b20d1aefd5398a84d9d84327 100644 (file)
@@ -359,15 +359,13 @@ static void
 nmea_set_waypoint_time(waypoint* wpt, struct tm* time, int microseconds)
 {
   if (time->tm_year == 0) {
-    wpt->creation_time = ((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec;
-    wpt->microseconds = microseconds;
+    wpt->SetCreationTime(((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec, microseconds);
     if (wpt->wpt_flags.fmt_use == 0) {
       wpt->wpt_flags.fmt_use = 1;
       without_date++;
     }
   } else {
-    wpt->creation_time = mkgmtime(time);
-    wpt->microseconds = microseconds;
+    wpt->SetCreationTime(mkgmtime(time), microseconds);
     if (wpt->wpt_flags.fmt_use != 0) {
       wpt->wpt_flags.fmt_use = 0;
       without_date--;
index ea14f997797055b26ef7e5772bbb95cb01b8da13..fbfa3fa5c70d1aeb7215304fae64182e8a074693 100644 (file)
@@ -527,7 +527,7 @@ osm_node(const char* args, const char** attrv)
     } else if (strcmp(avp[0], "lon") == 0) {
       wpt->longitude = atof(avp[1]);
     } else if (strcmp(avp[0], "timestamp") == 0) {
-      wpt->creation_time = xml_parse_time(avp[1], &wpt->microseconds);
+      wpt->creation_time = xml_parse_time(avp[1]);
     }
 
     avp += 2;
index 6cb77fb947927a16e08d5048521d71c23b820af0..5023dadd916b5dd550f8f4cc8828a2cbdd9ffc58 100644 (file)
@@ -507,7 +507,7 @@ palmdoc_disp(const waypoint *wpt)
 
       logpart = xml_findfirst(curlog, "groundspeak:date");
       if (logpart) {
-        logtime = xml_parse_time(logpart->cdata, NULL);
+        logtime = xml_parse_time(logpart->cdata);
         logtm = localtime(&logtime);
         if (logtm) {
           docprintf(15,
index 5428160710aa54753495589b7ba615ed67003bbe..432d645c6162123402e44f7c61bd50dcaa57c38e 100644 (file)
@@ -465,7 +465,7 @@ int ppdb_read_wpt(route_head *head, int isRoute)
         if (ppdb_decode_tm(str, &tm)) {
           tm.tm_year -= 1900;
           tm.tm_mon--;
-          wpt_tmp->creation_time = mkgmtime(&tm);
+          wpt_tmp->SetCreationTime(mkgmtime(&tm));
         }
         break;
       case 5:          /* name */
index 5eb127a9a1c07520ea42b2f2fdd4ff14737ef6d4..d059488994eacaacbc577042d20fdbe51a209d3c 100644 (file)
@@ -203,7 +203,7 @@ text_disp(const waypoint *wpt)
 
       logpart = xml_findfirst(curlog, "groundspeak:date");
       if (logpart) {
-        logtime = xml_parse_time(logpart->cdata, NULL);
+        logtime = xml_parse_time(logpart->cdata);
         logtm = localtime(&logtime);
         if (logtm) {
           gbfprintf(file_out,
index a55d8254d180388ea75e032edd0335e0a44dd0af..7b6de5f67a6a97ee98aa125a2a87bf2b6749d3fd 100644 (file)
@@ -947,7 +947,7 @@ unicsv_parse_one_line(char *ibuf)
 
     case fld_iso_time:
       is_localtime = 2;        /* fix result */
-      wpt->creation_time = xml_parse_time(s, &wpt->microseconds);
+      wpt->SetCreationTime(xml_parse_time(s));
       break;
 
     case fld_time:
@@ -1149,17 +1149,17 @@ unicsv_parse_one_line(char *ibuf)
         struct tm tm;
         tm = *gmtime(&t);
         if (opt_utc) {
-          wpt->creation_time = mkgmtime(&tm);
+          wpt->SetCreationTime(mkgmtime(&tm));
         } else {
-          wpt->creation_time = mklocaltime(&tm);
+          wpt->SetCreationTime(mklocaltime(&tm));
         }
       } else {
-        wpt->creation_time = t;
+        wpt->SetCreationTime(t);
       }
     } else if (time >= 0) {
-      wpt->creation_time = time;
+      wpt->SetCreationTime(time);
     } else if (date >= 0) {
-      wpt->creation_time = date;
+      wpt->SetCreationTime(date);
     } else if (ymd.tm_year || ymd.tm_mon || ymd.tm_mday) {
       if (ymd.tm_year < 100) {
         if (ymd.tm_year <= 70) {
index 537a7fbb79f46f68696a5920a3f1f6c278b8f690..176965ab06551ad2a003bdff76a18f06fbf5188b 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include <QtCore/QDebug>
 
 #include "defs.h"
 #include "cet_util.h"
@@ -667,9 +668,10 @@ waypoint::CreationTimeXML() const
     return NULL;
   }
 
-  QDateTime dt = QDateTime::fromTime_t(creation_time);
+  QDateTime dt = GetCreationTime();
   dt = dt.addMSecs(MICRO_TO_MILLI(microseconds));
   dt = dt.toUTC();
+// qDebug() << dt.toString("dd.MM.yyyy hh:mm:ss.zzz")  << " CML " << microseconds;
 
   const char* format = "yyyy-MM-ddTHH:mm:ssZ";
   if (dt.time().msec()) {
index 5336c72fd9b227177d2df6286c4ddc1729f55a74..5eab13051e2c7b127cf49142cb65c32703dab1cc 100644 (file)
@@ -173,7 +173,7 @@ void wfff_chan(const char *args, const char **unused)
 void wfff_first(const char *args, const char **unused)
 {
   if (args) {
-    ap_first = xml_parse_time(args, NULL);
+    ap_first = xml_parse_time(args);
   }
 }
 
index 59efe39fcb7fe4c7ec3ae55c5824c9eb58f050e4..e6827716b85f75a19c285723d64a3d4e97547e4b 100644 (file)
@@ -112,7 +112,7 @@ xol_shape(const char *args, const char **attrv)
       }
     } else if (strcmp(avp[0], "timestamp") == 0) {
       if (wpt) {
-        wpt->creation_time = xml_parse_time(avp[1], &wpt->microseconds);
+        wpt->creation_time = xml_parse_time(avp[1]);
       }
     } else if (strcmp(avp[0], "icon") == 0) {
       if (wpt) {